#include <bits/stdc++.h>

using namespace std;

int dir[4][2]={0,1,1,0,0,-1,-1,0};
int deep=0;
int max_deep=0;

void dfs(vector<vector<int>>& graph,vector<vector<bool>>& visited,int row,int col)
{
    for(int i=0;i<4;i++)
    {
        int row_pos=row+dir[i][0];
        int col_pos=col+dir[i][1];
        if(row_pos<0 || row_pos>=(int)graph.size() || col_pos<0 || col_pos>=(int)graph[0].size())
        {
            continue;
        }
        if(graph[row_pos][col_pos]==1 && visited[row_pos][col_pos]==false)
        {
            deep++;
            visited[row_pos][col_pos]=true;
            dfs(graph,visited,row_pos,col_pos);
        }
    }
}

int main()
{
    int n,m;
    cin>>n>>m;
    vector<vector<int>> graph(n,vector<int>(m,0));
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            cin>>graph[i][j];
        }
    }
    vector<vector<bool>> visited(n,vector<bool>(m,false));
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(graph[i][j]==1 && visited[i][j]==false)
            {
                deep++;
                visited[i][j]=true;
                dfs(graph,visited,i,j);
                max_deep=max(deep,max_deep);
                deep=0;
            }
        }
    }
    cout<<max_deep<<endl;
    return 0;
}